﻿using System.Collections.Generic;
using Flux.Data.Tiles;

namespace Flux.Data.Layers
{
	public class TileLayer
		: LayerBase
	{
		private readonly Tile[,] _tiles;
		public Tile[,] Tiles
		{
			get { return _tiles; }
		}

		public int TileWidth { get; set; }
		public int TileHeight { get; set; }

		public Tile this[int x, int y]
		{
			get
			{
				return _tiles[x,y];
			}
		}

		public TileLayer(int width, int height)
		{
			Width = width;
			Height = height;
			_tiles = new Tile[Width, Height];
			Clear();
		}

		public void Add(Tile tile)
		{
			tile.Width = TileWidth;
			tile.Height = TileHeight;
			_tiles[tile.X, tile.Y] = tile;
		}

		public void Clear()
		{
			for (var y = 0; y < Height; y++)
			{
				for (var x = 0; x < Width; x++)
				{
					_tiles[x, y] = null;
				}
			}
		}

		public void Remove(Tile tile)
		{
			_tiles[tile.X, tile.Y] = null;
		}
	}
}